package com.lettcode;

/**
 * @Description
 * @Author Jlis
 * @Date 2021/7/21
 * @Version 1.0
 */
public class Lc0007 {
    public static void main(String[] args) {
        System.out.println(reverse(1534236469));
    }
    public static int reverse(int x) {
        if (x<-2147483647 || (x > 2147483646)) {
            return 0;
        }
        boolean isLeftZero = false;
        if(x < 0){
            isLeftZero = true;
        }
        int tmp = Math.abs(x);
        int ret = 0;
        while(true){
            int t =   tmp % 10;
            if(ret > 214748364){
                return 0;
            }
            ret = ret * 10 + t;
            tmp = tmp / 10;
            if(tmp == 0){
                break;
            }
        }
        if(isLeftZero){
            ret = 0 - ret;
        }
        return ret;
    }
}
